package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.repository;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.FileUploadLogVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.User;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.FileUploadLogRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.UserRepository;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.entities.FileUploadLog;
import com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.mapper.FileUploadLogDAO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author huheng
 * @date 2019/5/29 2:53 PM
 */
@Service
public class FileUploadLogRepositoryImpl implements FileUploadLogRepository {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private FileUploadLogDAO fileUploadLogDAO;

    @Override
    public int insertFileUploadLog(FileUploadLogVo fileUploadLogVo) {
        User user = userRepository.getCurrentUser();
        if (fileUploadLogVo == null) {
            return 0;
        }
        fileUploadLogVo.setCreator(user.getUserCode());
        FileUploadLog log = new FileUploadLog();
        BeanUtils.copyProperties(fileUploadLogVo, log);
        return fileUploadLogDAO.insert(log);
    }
}
